<template>
  <div class="detail-action">
    <div class="state">
      <span class="iconfont" :class="[status.icon]"></span>
      <p>{{status.label}}</p>
    </div>
    <div class="info">
      <p>订单编号：{{order.id}}</p>
      <p>下单时间：{{order.createTime}}</p>
    </div>
    <div class="btn">
      <!-- 待付款状态下要显示的按钮 -->
      <template v-if="order.orderState === 1">
        <XtxButton @click="$router.push('/member/pay?id='+ order.id)" type="primary" size="small">立即付款</XtxButton>
        <XtxButton @click="handlerCancel(order)" type="gray" size="small">取消订单</XtxButton>
      </template>
      <!-- 待发货状态下要显示的按钮 -->
      <template v-if="order.orderState === 2">
        <XtxButton @click="$router.push(`/member/checkout?orderId=${order.id}`)" type="primary" size="small">再次购买</XtxButton>
      </template>
      <!-- 待收货状态下要显示的按钮 -->
      <template v-if="order.orderState === 3">
        <XtxButton @click="handlerConfirm(order)" type="primary" size="small">确认收货</XtxButton>
        <XtxButton @click="$router.push(`/member/checkout?orderId=${order.id}`)" type="plain" size="small">再次购买</XtxButton>
      </template>
      <!-- 待评价状态下要显示的按钮 -->
      <template v-if="order.orderState === 4">
        <XtxButton @click="$router.push(`/member/checkout?orderId=${order.id}`)" type="primary" size="small">再次购买</XtxButton>
        <XtxButton @click="$router.push(`/member/evaluate/${order.id}`)" type="plain" size="small">评价商品</XtxButton>
        <XtxButton type="gray" size="small">申请售后</XtxButton>
      </template>
      <!-- 已完成状态下要显示的按钮 -->
      <template v-if="order.orderState === 5">
        <XtxButton @click="$router.push(`/member/checkout?orderId=${order.id}`)" type="primary" size="small">再次购买</XtxButton>
        <XtxButton type="plain" size="small" @click="$router.push(`/member/evaluate-detail/${order.id}`)">查看评价</XtxButton>
        <XtxButton type="gray" size="small">申请售后</XtxButton>
      </template>
    </div>
    <!-- 取消订单弹窗组件 -->
    <Teleport to="body">
      <OrderCancel ref="orderCancelCom" />
    </Teleport>
  </div>
</template>

<script>
import { useCancel, useConfirm } from '../index.vue'
import OrderCancel from './order-cancel.vue'
import { computed } from '@vue/reactivity'
export default {
  name: 'OrderDetailAction',
  components: {
    OrderCancel
  },
  props: {
    order: {
      type: Object,
      default: () => ({})
    }
  },
  setup (props) {
    const status = computed(() => {
      const orderState = props.order.orderState
      let status = {}
      switch (orderState) {
        case 1:
          status = { label: '等待付款', icon: 'icon-order-unpay' }
          break
        case 2:
          status = { label: '等待发货', icon: 'icon-order-deliver' }
          break
        case 3:
          status = { label: '等待收货', icon: 'icon-order-receive' }
          break
        case 4:
          status = { label: '等待评价', icon: 'icon-order-comment' }
          break
        case 5:
          status = { label: '交易完成', icon: 'icon-order-complete' }
          break
        case 6:
          status = { label: '交易关闭', icon: 'icon-order-cancel' }
          break
      }
      return status
    })
    return { status, ...useCancel(), ...useConfirm() }
  }
}
</script>

<style lang="less" scoped>
.detail-action {
  height: 180px;
  width: 100%;
  display: flex;
  align-items: center;
  .state {
    width: 220px;
    text-align: center;
    .iconfont {
      font-size: 40px;
      color: @xtxColor;
    }
    p {
      font-size: 16px;
      color: #666;
      margin-bottom: 10px;
    }
  }
  .info {
    width: 240px;
    line-height: 30px;
    p {
      color: #999;
    }
  }
  .btn {
    flex: 1;
    text-align: right;
    margin-right: 100px;
    .xtx-button {
      margin-left: 20px;
    }
  }
}
</style>
